package org.example.qweqq.controller;

import org.example.qweqq.pojo.Result;
import org.example.qweqq.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.UUID;

@RestController
public class FileUploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String of = file.getOriginalFilename();
        String filename = UUID.randomUUID().toString()+of.substring(of.lastIndexOf("."));
        //file.transferTo(new File("C:\\Users\\zhaow\\Desktop\\files\\"+filename));
        String url = AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }

}
